#ifndef __SINGLE_LIST_H
#define __SINGLE_LIST_H

#include <stdlib.h>
#include <stdbool.h>

#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

#define container_of(ptr, type, member) ({              \
    const typeof(((type *)0)->member) *__mptr = (ptr);  \
    (type *)((char *)__mptr - offsetof(type, member));  \
})

#define list_for_each_entry(pos, head, member)                      \
    for(pos = container_of((head)->next, typeof(*pos), member);     \
    &pos->member != NULL;                                           \
    pos = container_of(pos->member.next, typeof(*pos), member))

struct list;

struct list {
    struct list *next;
};

void list_del(struct list *head,struct list *delete);
void list_add_head(struct list *head,struct list *insert);
void list_del_head(struct list *head);
void list_add_tail(struct list *head,struct list *insert);
void list_del_tail(struct list *head);
bool list_is_empty(struct list *head);

#endif/*__SINGLE_LIST_H*/
